package com.maxd.service.pay;

import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.model.PayDetails;
import com.maxd.model.PublisherOrderDtoBean;
import com.maxd.respository.order.OrderJpaRepository;
import com.maxd.respository.order.OrderRepository;
import com.maxd.respository.pay.PayDetailsJpaRepository;
import com.maxd.respository.pay.PayDetailsRepository;
import com.maxd.service.order.OrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
 * 支付订单接口service实现类
 */
@Service
public class PayDetailsServiceImpl implements PayDetailsService {


    @Autowired
    private PayDetailsJpaRepository payDetailsJpaRepository;
    @Autowired
    private PayDetailsRepository payDetailsRepository;


    @Override
    public PayDetails saveBody(PayDetails payDetails) {
        return payDetailsJpaRepository.save(payDetails);
    }

    @Override
    public PayDetails selectByOrderId(String orderId) {
        return payDetailsRepository.selectByOrderId(orderId);
    }

    @Override
    public PayDetails selectById(Long id) {
        return payDetailsRepository.selectById(id);
    }

    @Override
    public int updateState(Long id, Integer state,Date time) {
        return payDetailsRepository.updateState(id,state,time);
    }

    @Override
    public Page<Map<String,Object>> selectPayDetails(Pageable pageable, String phone, String startTime, String endTime) {
        if(StringUtils.isNotBlank(phone)){
            return payDetailsRepository.selectPayDetails(pageable,phone,startTime,endTime);
        }else{
            return payDetailsRepository.selectPayDetails(pageable,startTime,endTime);
        }
    }

    @Override
    public Page<Map<String,Object>> selectPayDetailsByUserId(Pageable pageable, Long userId, String startTime, String endTime) {
        return payDetailsRepository.selectPayDetailsByUserId(pageable,userId,startTime,endTime);
    }




}
